1 /* 2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021 3 License: [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License]. 4 Authors: Marcelo S. N. Mancini 5 6 Copyright Marcelo S. N. Mancini 2018 - 2021. 7 Distributed under the CC BY-4.0 License. 8 (See accompanying file LICENSE.txt or copy at 9 https://creativecommons.org/licenses/by/4.0/ 10 */ 11 12 module hip.api.graphics.g2d.renderer2d; 13 14 import hip.api.internal; 15 public import hip.api.data.image; 16 public import hip.api.graphics.color; 17 public import hip.api.renderer.texture; 18 public import hip.api.data.font; 19 public import hip.api.graphics.text; 20 public import hip.api.graphics.g2d.animation; 21 public import hip.api.graphics.g2d.g2d_binding; 22 23 version(ScriptAPI) version = DefineOverloadings; 24 version(DefineOverloadings) 25 { 26 private alias G2D = hip.api.graphics.g2d.g2d_binding; 27 ///Sets the font for the next drawText commands 28 void setFont(IHipFont font){G2D.setFont(font);} 29 void setFont(typeof(null)){G2D.setFont(cast(IHipFont)null);} 30 ///Sets the font using HipAssetManager.loadFont 31 void setFont(IHipAssetLoadTask task){G2D.setFontDeferred(task);} 32 33 //Float overloading for drawLine 34 void drawLine(float x1, float y1, float x2, float y2, HipColor color = HipColor.no) 35 { 36 hip.api.graphics.g2d.g2d_binding.drawLine(cast(int)x1, cast(int)y1, cast(int)x2, cast(int)y2, color); 37 } 38 void drawRectangle(float x, float y, float width, float height, HipColor color = HipColor.no) 39 { 40 hip.api.graphics.g2d.g2d_binding.drawRectangle(cast(int)x, cast(int)y, cast(int)width, cast(int)height, color); 41 } 42 43 ///Circle API 44 void drawCircle(int x, int y, int radius, HipColor color = HipColor.no, int precision = 24) 45 { 46 hip.api.graphics.g2d.g2d_binding.drawEllipse(x, y, radius, radius, 360, color, precision); 47 } 48 void drawCircle(float x, float y, float radius, HipColor color = HipColor.no, int precision = 24) 49 { 50 hip.api.graphics.g2d.g2d_binding.drawEllipse(cast(int)x, cast(int)y, cast(int)radius, cast(int)radius, 360, color, precision); 51 } 52 53 void fillCircle(int x, int y, int radius, HipColor color = HipColor.no, int precision = 24) 54 { 55 hip.api.graphics.g2d.g2d_binding.fillEllipse(cast(int)x, cast(int)y, cast(int)radius, cast(int)radius, 360, color, precision); 56 } 57 void fillCircle(float x, float y, float radius, HipColor color = HipColor.no, int precision = 24) 58 { 59 hip.api.graphics.g2d.g2d_binding.fillEllipse(cast(int)x, cast(int)y, cast(int)radius, cast(int)radius, 360, color, precision); 60 } 61 /// 62 63 ///Float overloading for fillEllipse 64 void fillEllipse(float x, float y, float width, float height, int degrees = 360, HipColor color = HipColor.no, int precision = 24) 65 { 66 hip.api.graphics.g2d.g2d_binding.fillEllipse(cast(int)x, cast(int)y, cast(int)width, cast(int)height, degrees, color, precision); 67 } 68 69 ///Float overloading for drawEllipse 70 void drawEllipse(float x, float y, float width, float height, int degrees = 360, HipColor color = HipColor.no, int precision = 24) 71 { 72 hip.api.graphics.g2d.g2d_binding.drawEllipse(cast(int)x, cast(int)y, cast(int)width, cast(int)height, degrees, color, precision); 73 } 74 75 ///Float overloading for fillRectangle 76 void fillRectangle(float x, float y, float width, float height, HipColor color = HipColor.no) 77 { 78 hip.api.graphics.g2d.g2d_binding.fillRectangle(cast(int)x, cast(int)y, cast(int)width, cast(int)height, color); 79 } 80 81 version(Have_util) 82 { 83 import hip.util.reflection:isTypeArrayOf; 84 85 pragma(inline, true) 86 { 87 //Struct compatible with float[2] or float[2] 88 void drawLine(T)(in T start, in T end, HipColor color = HipColor.no) 89 if(isTypeArrayOf!(float, T, 2)) 90 { 91 const float[2] s = *cast(const(float[2])*)cast(const(void*))&start; 92 const float[2] e = *cast(const(float[2])*)cast(const(void*))&end; 93 drawLine(s[0], s[1], e[0], e[1], color); 94 } 95 ///Struct compatible with float[4] or float[4] 96 void fillRectangle(T)(in T r, HipColor color = HipColor.no) 97 if(isTypeArrayOf!(float, T, 4)) 98 { 99 const float[4] a = *cast(const(float[4]*))cast(const(void*))&r; 100 fillRectangle(a[0], a[1], a[2], a[3], color); 101 } 102 void drawRectangle(T)(in T r, HipColor color = HipColor.no) 103 if(isTypeArrayOf!(float, T, 4)) 104 { 105 const float[4] a = *cast(const(float[4]*))cast(const(void*))&r; 106 drawRectangle(a[0], a[1], a[2], a[3], color); 107 } 108 } 109 110 ///Rect overload for fillRectangle 111 } 112 }